package com.pj.hellomvvm.ui.fragment.other


import android.hardware.Camera
import android.os.Bundle
import android.view.View
import com.pj.common.annotation.LayoutParam
import com.pj.common.base.BaseViewModel
import com.pj.common.base.topbar.BaseTopBarFragment
import com.pj.hellomvvm.R
import com.pj.hellomvvm.databinding.LayoutTextViewBinding


@LayoutParam(layout = R.layout.layout_text_view, title = R.string.title_fragment_camera_info)
class OtherCameraInfoFragment : BaseTopBarFragment<BaseViewModel, LayoutTextViewBinding>() {
    lateinit var camera:Camera
    override fun initData(view: View, savedInstanceState: Bundle?) {
        super.initData(view, savedInstanceState)
         camera = Camera.open()

         val parameters = camera.parameters

         val params = parameters.flatten().replace(";", "\n")
         mCBinding.text.setText(params)
//        mCBinding.text.text = getCameraResolution(2).toString()
    }

 /*   private fun getCameraResolution(camNum: Int): SizeF? {
        var size:SizeF ?= SizeF(0f, 0f)
        val manager = requireActivity().getSystemService(Context.CAMERA_SERVICE) as CameraManager?
        try {
            val cameraIds = manager!!.cameraIdList
            if (cameraIds.size > camNum) {
                val character: CameraCharacteristics =
                    manager.getCameraCharacteristics(cameraIds[camNum])
                size = character.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE)
            }
        } catch (e: CameraAccessException) {
            LogUtils.e(e.message)
        }
        return size
    }*/

    override fun onDestroy() {
        camera.release()
        super.onDestroy()
    }
}